<style lang='scss' scoped>
.main-wrap {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  .main {
    height: 100%;
    display: flex;
    overflow: hidden;
    .content-wrap {
      width: 100%;
      display: flex;
      overflow: hidden;
      // flex-direction: column;
      background: #f2f2f2;
      //   padding-left: 200px;
      .content {
        flex: 1;
        overflow-y: auto;
        
      }
    }
  }
}
</style>

<template>
  <div class="main-wrap" v-loading.fullscreen.lock="loading">
    <ZHHead :userInfo="userInfo"/>

    <!-- <ZHMenu :loginUserMenus="loginUserMenus"/> -->
    <div class="main">
      <ZHMenu :systemMenus="loginUserMenus"/>

      <div class="content-wrap">
        <!-- <HistoryTab/> -->
        <router-view class="content"></router-view>
      </div>
    </div>
    <!-- <ZHFooter/> -->
  </div>
</template>


<script>
//引入组件
import ZHMenu from "../components/common/Menu";
import ZHHead from "../components/common/Header";
import ZHFooter from "../components/common/Footer";
import HistoryTab from "src/components/common/HistoryTab";

import { mapGetters, mapActions } from "vuex";

import storage from 'src/utils/storage';
import fetch from "src/utils/fetch";
import API from "src/utils/api";
import notification from 'src/utils/notification';

// const ticket = GetQueryString('ticket');

// function GetQueryString(name) {
//   var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
//   var r = window.location.search.substr(1).match(reg);
//   if (r != null) return unescape(r[2]); return null;
// }

export default {
  name: "main",
  data() {
    return {
      activeIndex: 1,
      userInfo: '',
      loginUserMenus: '',
    };
  },
  components: { ZHMenu, ZHHead, HistoryTab, ZHFooter }, //注册组件
  computed: {
    ...mapGetters(["loading"])
  },
  created() {

    this.queryLoginUserMenus();

    // this.userInfo=storage.get("userInfo") ? storage.get("userInfo") : '';
    // this.loginUserMenus=storage.get('loginUserMenus') ? storage.get('loginUserMenus') : '';

    // // // 内部登录
    // // if(storage.get('isInnerLogin') == true){

    //   // nsso 登录判断
    //   const nssoLoginURL=API.NSSOLoginURL;

    //   if(!ticket){

    //     // 初次登陆
    //     return window.location.href=nssoLoginURL;
    //   }

    //   if( !storage.get("isLogin") ){
    //     //  如果ticket存在,未保存过用户信息，则向前置发起登录请求
    //     ticket && this.requestLogin();
    //   }else{
    //       sessionStorage.getItem('isLogin') && this.queryLoginUserMenus();
    //   }

    // storage.set('isLogin',true);
    // this.queryLoginUserMenus();
  },
  methods: {
    ...mapActions([
      'queryPageBtnMenus',
    ]),
    handleSelect() {

    },
    requestLogin() {

      let that = this;

      let params = {
        service: 'za-pre-stormeye-console',
        ticket: ticket,
      };

      // // 必须为get请求,否则
      fetch({
        url: '/index?ticket=' + ticket + '&service=za-pre-stormeye-console',
        type: "post",
        data: params,
        success: function (data) {

          storage.set('isLogin', true);
          that.userInfo = data.name;
          storage.set("userInfo", data.name);
          that.queryLoginUserMenus();


        },
        error: function (resData) {
          notification.warning(resData.returnMsg);
        }
      })


    },
    queryLoginUserMenus() {
      let that = this;
      // fetch({
      //   url: API.batch.permissionMgr.showMyMenu,
      //   type: "post",
      //   data: '',
      //   showRegionLoading: true,
      //   success: function(data) {


      let data = [
        {
          "children": [{
            "code": "FACL",
            "id": 104001,
            "name": "基础信息配置",
            "path": "/prdConfig/baseInfo",
            "permissions": [],
            "sortId": 1,

          },
          {
            "code": "OSSJH",
            "id": 104002,
            "name": "接口配置",
            "path": "/prdConfig/interface",
            "permissions": [],
            "sortId": 1
          },

            // {
            //   "code": "OSSJH",
            //   "id": 104002,
            //   "name": "定时任务",
            //   "path": "/prdConfig/timing",
            //   "permissions": [],
            //   "sortId": 1
            // },
          ],
          "code": "XTPZ",
          "iconCls": "el-icon-date",
          "id": 104,
          "name": "产品配置",
          'path': '/prdConfig',
          "sortId": 4,
          "iconCls":"icon-product-setup"
        },

        {
          "children": [{
            "code": "FACL",
            "id": 104001,
            "name": "Handler列表",
            "path": "/handlerLib/list",
            "permissions": [],
            "sortId": 1
          },
          {
            "code": "OSSJH",
            "id": 104002,
            "name": "Handler格转",
            "path": "/handlerLib/format",
            "permissions": [],
            "sortId": 1
          },
          {
            "code": "OSSJH",
            "id": 104002,
            "name": "HandlerMock",
            "path": "/handlerLib/mock",
            "permissions": [],
            "sortId": 1
          },
          ],
          "code": "XTPZ",
          "id": 104,
          'path': '/handlerLib',
          "name": "Handler库",
          "sortId": 4,
          "iconCls":"icon-handler"
        },

        {
          "children": [{
            "code": "FACL",
            "id": 104001,
            "name": "Router列表",
            "path": "/routerLib/list",
            "permissions": [],
            "sortId": 1
          },
          // {
          //   "code": "OSSJH",
          //   "id": 104002,
          //   "name": "Router编排",
          //   "path": "/routerLib/layout",
          //   "permissions": [],
          //   "children": [{
          //     "code": "FACL",
          //     "id": 104001,
          //     "name": "BindCardRouter列表",
          //     "path": "/routerLib/layout/bindCardRouter",
          //     "permissions": [],
          //     "sortId": 1
          //   },],
          //   "sortId": 1
          // },
          {
            "code": "OSSJH",
            "id": 104002,
            "name": "Router格转",
            "path": "/routerLib/format",
            "permissions": [],
            "sortId": 1
          },
          ],
          "code": "XTPZ",
          "id": 104,
          'path': '/routerLib',
          "name": "Router库",
          "sortId": 4,
          "iconCls":"icon-product-router"
        },
        // {
        //   "children": [
        //   ],
        //   "code": "XTPZ",
        //   "iconCls": "el-icon-date",
        //   "id": 104,
        //   'path': '/prdLib/index',
        //   "name": "产品库",
        //   "sortId": 4
        // },

        {
          "iconCls": "icon-zookeeper",
          'path': '/zooKeeper/index',
          "name": 'zooKeeper配置',

        },

        // {
        //   "children": [
        //     {
        //       "iconCls": "el-icon-date",
        //       'path': '/prdQuery/dataQuery',
        //       "name": '数据查询',
        //     }
        //   ],
        //   "iconCls": "el-icon-date",
        //   'path': '/prdQuery',
        //   "name": '生产验证查询',

        // },

      ];

      that.loginUserMenus = data;
      storage.set("loginUserMenus", data);
      storage.set("userInfo", '管理员');
      this.userInfo = {
        name: '管理员',
        menu: data,
      }
      //   },
      //   error: function(res) {
      //     notification.error(res.returnMsg);
      //   }
      // });
    },
    handleClose(key, keyPath) {
      // console.log("close", key, keyPath);
    },
  }

};
</script>


